/*
 * 文件名: BaseActivity.java
 * 版    权：  Copyright PingAn Technology All Rights Reserved.
 * 描    述: [头部的基类]
 * 创建人: EX-LIUHONGBAO001
 * 创建时间: 2011-12-20
 * 
 * 修改人：
 * 修改时间:
 * 修改内容：[修改内容]
 */
package com.longevityassistant.activity;

import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import app.utils.CommonUtils;

/**
 * [头部基类]<BR>
 * [头部功能]
 * @author EX-LIUHONGBAO001
 * @version [Android PABank C01, 2011-12-21]
 */
public abstract class BaseActivity extends MenuActivity implements OnClickListener {
	/**
	 * debug Tag
	 */
	protected final String TAG = this.getClass().getSimpleName();
	/**
	 * 顶部标题
	 */
	private TextView title;
	/**
	 * 顶部左右按钮
	 */
	protected Button imageButton1, imageButton2;
	/**
	 * 顶部头像
	 */
	private ImageView showLogo;
	/**
	 * title
	 */
	private TextView tvTitle;
	/**
	 * 头部布局对象
	 */
	private RelativeLayout topRelativeLayout;
	/**
	 * MENU_COUNT
	 */
	public static final int MENU_COUNT = 5;
	/**
	 * llBase
	 */
	private LinearLayout llBase;
	
	/**
	 * 封装
	 */
	public Button getImageButton1() {
		return imageButton1;
	}
	public void setImageButton1(Button imageButton1) {
		this.imageButton1 = imageButton1;
	}
	public Button getImageButton2() {
		return imageButton2;
	}
	public void setImageButton2(Button imageButton2) {
		this.imageButton2 = imageButton2;
	}
	public ImageView getShowLogo() {
		return showLogo;
	}
	public void setShowLogo(ImageView showLogo) {
		this.showLogo = showLogo;
	}
	public TextView getTvTitle() {
		return tvTitle;
	}
	public void setTvTitle(TextView tvTitle) {
		this.tvTitle = tvTitle;
	}
	public void setTopTitle(int topTitle) {
		title.setText(topTitle);
	}
	public void setTopTitle(String topTitle) {
		title.setText(topTitle);
	}
	public void setTopButtonLeftIcon(int topLeftIcon) {
		imageButton1.setBackgroundResource(topLeftIcon);
	}
	public void setTopButtonRightIcon(int topRightIcon) {
		imageButton2.setBackgroundResource(topRightIcon);
	}
	public void setImageText(int topLeftICon) {
	}
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		CommonUtils.add(this);
		getXml();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		CommonUtils.remove(this);
	}

	/**
	 * setContentView
	 */
	@Override
	public void setContentView(View view) {
		if (llBase.getChildCount() > 1) {
			llBase.removeViewAt(1);
		}
		LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1);
		llBase.addView(view, lp);
	}

	/**
	 * setContentView
	 */
	@Override
	public void setContentView(int layoutResID) {
		View view = LayoutInflater.from(this).inflate(layoutResID, null);
		setContentView(view);
	}

	/**
	 * 初始化
	 */
	public void getXml() {
		super.setContentView(R.layout.home_include_title);
		topRelativeLayout = (RelativeLayout) super.findViewById(R.id.lin_top);
		title = (TextView) super.findViewById(R.id.tv_title);
		imageButton1 = (Button) super.findViewById(R.id.first_img);
		imageButton1.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				backKey();
			}
		});
		imageButton2 = (Button) super.findViewById(R.id.home_img);
		showLogo = (ImageView) super.findViewById(R.id.logo);
		tvTitle = (TextView) super.findViewById(R.id.tv_title);
		llBase = (LinearLayout) super.findViewById(R.id.base);
	}
	
	
	@Override
	public void onClick(DialogInterface dialog, int which) {
		backKey();
	}
	
	/**
	 * 头部标题
	 */
	public String getTopTitle() {
		return title.getText().toString();
	}
	
	
	/**
	 * 头部回退键
	 * 头部回退键
	 */
	public void backKey() {
		this.finish();
	}
	/**
	 * 头部回退键
	 * 头部回退键
	 */
	public void backKey(Context context) {
		finish();
	}
	/**
	 * [隐藏头部]<BR>
	 * [隐藏头部]
	 */
	public void setTopGone() {
		topRelativeLayout.setVisibility(View.GONE);
	}
	/**
	 * 设置头部有图片Logo(比如登录)
	 */
	public void	setTopImgTitle(int resid){
        this.getTvTitle().setVisibility(View.GONE);
		this.getShowLogo().setVisibility(View.VISIBLE);
		this.getShowLogo().setBackgroundResource(resid);
	}

}